package com.example.new4.views;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.TextView;


import com.example.new4.R;
import com.example.new4.application.MyApplication;
import com.example.new4.base.BaseActivity;
import com.example.new4.database.DBHelper;
import com.example.new4.database.DBHelper2;
import com.example.new4.entity.Course;
import com.example.new4.entity.Student;
import com.example.new4.utils.SpUtils;

import jakarta.inject.Inject;

public class MainActivity extends BaseActivity implements View.OnClickListener {

    private TextView mText;
    @Inject
    public Student mStudent1;
    @Inject
    public Student mStudent2;
    @Inject
    public DBHelper mDBHelper;
    @Inject
    public Course mCourse1;
    @Inject
    public Course mCourse2;
    @Inject
    public DBHelper2 mDBHelper2;
    @Inject
    public SpUtils mSpUtils;
    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }
    @Override
    public void init() {

        //Student
        mText = findViewById(R.id.text);
        mText.setOnClickListener(this);
        /*DaggerAllComponent
                .builder()
                .studentModule(new StudentModule())
                .dBModule(new DBModule(this))
                .build()
                .injectMainActivity(this);*/
        ((MyApplication)getApplication()).getAllComponent().injectMainActivity(this);
        Log.d("asdf", "Main mStudent1 === " + mStudent1.hashCode());
        Log.d("asdf", "Main mStudent2 === " + mStudent2.hashCode());
        mStudent1.setStudent_code("22");
        mStudent1.setStudent_id(1);
        mStudent1.setStudent_name("张三四");
        mStudent1.setUsername("abcdef");
        mStudent1.setPassword("123456");
        mStudent1.setClass_name("2024");
        Log.d("asdf", "Main mDBHelper === " + mDBHelper.hashCode());
        mDBHelper.insertStudent(mStudent1);
//        mDBHelper.deleteStudentByName("张三四");

        //Course
        Log.d("asdf", "Main mCourse1 === " + mCourse1.hashCode());
        Log.d("asdf", "Main mCourse2 === " + mCourse2.hashCode());
        mCourse1.setCourse_code("0005");
        mCourse1.setCourse_id(1);
        mCourse1.setCourse_name("计算机网络");
        Log.d("asdf", "Main mDBHelper2 === " + mDBHelper2.hashCode());
        mDBHelper2.insertCourse(mCourse1);
//        mDBHelper2.deleteCourseByName("计算机网络");

        //SpUtils
        // 存入数据
        mSpUtils.putString("key", "Hello, InfoActivity!");
        Log.d("asdf","Main mmSpUtils === " + mSpUtils.hashCode());

    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(MainActivity.this, InfoActivity.class);
        startActivity(intent);
    }
}